<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加主要备件</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <link rel="stylesheet" href="../../../../../css/mui.min.css">
    <link rel="stylesheet" href="../../../../../css/global.css">
    <link rel="stylesheet" href="../../../../../css/style.css">
    <link rel="stylesheet" href="../../../../../css/mui.picker.css">
    <link rel="stylesheet" href="../../../../../css/mui.poppicker.css">
    <style>
        button:disabled {
            opacity: 1;
        }
    </style>
</head>

<body>
<header class="mui-bar mui-bar-nav">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 id="title" class="mui-title">添加主要备件</h1>
</header>
<div class="mui-content">
    <div class="details_con">
        <div hidden>
            <input type="hidden" id="ServiceNoticeId"/>
            <input type="hidden" id="instrumentNo"/>
            <input type="hidden" id="serviceNoV"/>
        </div>
        <div class="clum">
            <span class="name">服务编号</span>
            <span id="serviceNo" class="txt"></span>
        </div>
        <div class="clum">
            <span class="name">备件号<em class="t_red">*</em></span>
            <input type="text" id="partsCode" class="d_ipt" value="" placeholder="请输入"/>
        </div>
        <div class="clum">
            <span class="name">备件名称</span>
            <input type="text" id="partsName" class="d_ipt" value="" placeholder="请输入"/>
        </div>
        <div class="clum">
            <span class="name">备件序列号<em class="t_red">*</em></span>
            <input type="text" id="partsSerial" class="d_ipt" value="" placeholder="请输入"/>
        </div>
        <div class="clum">
            <span class="name">保修开始时间<em class="t_red"></em></span>
            <button id='partsWarrantyStart' type="button" class="selectDate">请选择保修开始时间</button>
        </div>
        <div class="clum">
            <span class="name">保修结束时间<em class="t_red"></em></span>
            <button id='partsWarrantyEnd' type="button" class="selectDate">请选择保修结束时间</button>
        </div>
        <div class="line"></div>
        <div class="btn_box">

            <span id="cancel" class="fl">取消</span>
            <span id="saveBtn" class="fr red">保存</span>
        </div>
        <div style="height: 50px;"></div>
    </div>
</div>

<!-- js代码 start -->

<!-- 基础js start -->
<script src="../../../../../js/mui.min.js"></script>
<script src="../../../../../js/utils/h.js"></script>
<script src="../../../../../js/constant.js"></script>
<script src="../../../../../js/common.js"></script>
<script src="../../../../../js/utils/base64.js"></script>
<script src="../../../../../js/utils/md5.js"></script>
<script src="../../../../../js/utils/sortMap.js"></script>
<script src="../../../../../js/utils/http.js"></script>
<script src="../../../../../js/app.js"></script>
<!-- 基础js end -->
<script src="../../../../../js/utils/rolldate.min.js"></script>
<script src="../../../../../js/mui.picker.js"></script>
<script src="../../../../../js/mui.poppicker.js"></script>
<script type="text/javascript" charset="utf-8">

    (function ($, doc) {
        $.init();

        // 取消方法
        h("#cancel").tap(function () {
            $.back()
        });

        $.plusReady(function () {
            var self = plus.webview.currentWebview();
            // 获取上一个页面传过来的参数并显示到页面
            h('#serviceNo').html(self.serviceNo);
            h('#serviceNoV').val(self.serviceNo);
            h('#ServiceNoticeId').val(self.ServiceNoticeId);
            h('#instrumentNo').val(self.instrumentNo);

            // 初始化时间控件 保修开始时间
            new Rolldate({
                el: '#partsWarrantyStart',
                format: 'YYYY-MM-DD hh:mm',
                beginYear: 2015,
                endYear: 2050,
                trigger: 'click',
                lang: {
                    title: '请选择保修开始时间',
                },
                confirm: function (date) {

                }
            })
            // 初始化时间控件 保修结束时间
            new Rolldate({
                el: '#partsWarrantyEnd',
                format: 'YYYY-MM-DD hh:mm',
                beginYear: 2015,
                endYear: 2050,
                trigger: 'click',
                lang: {
                    title: '请选择保修结束时间',
                },
                confirm: function (date) {

                }
            })

            // 保存草稿按钮触发事件
            h('#saveBtn').tap(function () {
                var partsCode = h("#partsCode").val();
                if (partsCode == undefined || partsCode == "") {
                    app.toast("请输入备件号");
                    return
                }
                var partsSerial = h("#partsSerial").val();
                if (partsSerial == undefined || partsSerial == "") {
                    app.toast("请输入备件序列号");
                    return
                }
                var partsWarrantyStart = h("#partsWarrantyStart").html();
                var partsWarrantyEnd = h("#partsWarrantyEnd").html();
                if ((partsWarrantyStart == undefined || partsWarrantyStart == "" || partsWarrantyStart == '请选择保修开始时间')&&(partsWarrantyEnd == undefined || partsWarrantyEnd == "" || partsWarrantyEnd == '请选择保修结束时间')) {
                    partsWarrantyStart = ""
                    partsWarrantyEnd = ""
                    // app.toast("请选择保修开始时间")
                    // return
                } else {
                    if (partsWarrantyEnd == undefined || partsWarrantyEnd == "" || partsWarrantyEnd == '请选择保修结束时间') {
                        app.toast("请选择保修结束时间")
                        return
                    }
                    if (partsWarrantyStart == undefined || partsWarrantyStart == "" || partsWarrantyStart == '请选择保修结束时间') {
                        app.toast("请选择保修开始时间")
                        return
                    }
                    if (stringYYYYMMDDHHMMToDate(partsWarrantyStart).getTime() > stringYYYYMMDDHHMMToDate(partsWarrantyEnd).getTime()) {
                        app.toast("保修结束时间不能小于保修开始时间")
                        return false
                    }
                }

                var partsSerial = h("#partsSerial").val()
                ajaxPost(BASE_URL + "cc/installation/quality/report/addMajorPart", {
                    "serviceNo": h("#serviceNoV").val(),
                    "enginnerId": app.getUser().enginnerId,
                    "partNumber": partsCode,
                    "partName": h("#partsName").val(),
                    "serialNumber": partsSerial,
                    "warrantyStartTime": partsWarrantyStart,
                    "warrantyEndTime": partsWarrantyEnd,
                    "instrumentNo": h("#instrumentNo").val()
                }, function (data) {
                    console.log(JSON.stringify(data))
                    if (data.code == 200) {
                        app.toast("添加成功")
                    } else {
                        app.toast("添加失败")
                    }
                    if (self.addType === 1) {
                        var mainSparePartsList = plus.webview.getWebviewById('view/service/report/installationquality/mainSpareParts/list.html');
                        if (mainSparePartsList) {
                            mainSparePartsList.evalJS('initData()')
                        }
                        self.close()
                    } else {
                        $.back()
                    }
                }, function (errorMsg) {
                    console.log(JSON.stringify(errorMsg))
                });


            })

        });
    }(mui, document));

</script>
<!-- js代码 end -->
</body>
</html>
